#!/bin/env bash

mkdir -p /orasvr/nbcsora/archived
# 修改密码错误次数和密码有效期
echo "RESET FAILED_LOGIN_ATTEMPTS  AND  PASSWORD_LIFE_TIME " >> /tmp/oracleinit.log
sqlplus / as sysdba <<EOF
-- 修改错误密码错误次数限制为无限次
alter profile default limit FAILED_LOGIN_ATTEMPTS unlimited;
-- 设置密码永久有效
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
quit
EOF

# 查询密码错误次数和密码有效期
result0=$(sqlplus / as sysdba <<EOF
set heading off feedback off
SELECT * FROM dba_profiles s WHERE s.profile='DEFAULT' AND resource_name='PASSWORD_LIFE_TIME';
SELECT * FROM dba_profiles WHERE resource_name = 'FAILED_LOGIN_ATTEMPTS';
exit;
EOF
)
echo "FAILED_LOGIN_ATTEMPTS  AND  PASSWORD_LIFE_TIME RESULT $result0" >> /tmp/oracleinit.log



echo "RESET db_recovery_file_dest_size  AND  db_recovery_file_dest, CLOSE audit_trail " >> /tmp/oracleinit.log
sqlplus / as sysdba <<EOF
alter system set db_recovery_file_dest_size=50G;
alter system set db_recovery_file_dest='/orasvr/nbcsora/archived';
-- 关闭数据库实例
shutdown immediate
quit
EOF
echo "sleep 15 s ，wait immediate shutdown" >> /tmp/oracleinit.log
sleep 15s

echo "开启归档模式" >> /tmp/oracleinit.log
sqlplus / as sysdba <<EOF
-- 启动到mount
startup mount
-- 开启归档模式
alter database archivelog;
-- 打开数据库
alter database open;
quit
EOF

echo "sleep 20 s ，wait database open" >> /tmp/oracleinit.log
sleep 20s

archiveLogList=$(sqlplus / as sysdba <<EOF
set heading off feedback off
archive log list;
exit;
EOF
)
echo "归档模式结果$archiveLogList" >> /tmp/oracleinit.log


# 关闭审计功能
echo "CLOSE AUDIT" >> /tmp/oracleinit.log
sqlplus / as sysdba <<EOF
-- 关闭审计功能
ALTER SYSTEM SET AUDIT_TRAIL='NONE' SCOPE=SPFILE;
-- 关闭数据库实例
shutdown immediate
quit
EOF

echo "sleep 15 s ，wait immediate shutdown" >> /tmp/oracleinit.log
sleep 15s

echo "STATUP" >> /tmp/oracleinit.log
sqlplus / as sysdba <<EOF
startup;
quit
EOF

result1=$(sqlplus / as sysdba <<EOF
set heading off feedback off
show parameter audit_trail;
exit;
EOF
)
echo "审计功能关闭结果$result1" >> /tmp/oracleinit.log


rm -f oracleinit.sh